package org.noworks.game.engine;

import java.awt.Point;

import org.newdawn.slick.Image;

/**
 * Sprite class to provide a simple container for an image, coordinates and
 * scale. Meant to be used for static images as of now.
 * 
 * @author Michael Nowak
 * 
 */
public class Sprite {
	private Image image; // Image for the sprite

	private float scale; // Scale of the image

	private float x; // X position of the image

	private float y; // Y position of the image

	public Sprite(Image image, float x, float y, float scale) {
		super();
		this.image = image;
		this.x = x;
		this.y = y;
		this.scale = scale;
	}

	/**
	 * Calls the Image's draw method scaling the position relative to the
	 * starting input and image size.
	 */
	public void draw() {
		image.draw(x * scale, y * scale, scale);
	}

	public Image getImage() {
		return image;
	}

	public float getScale() {
		return scale;
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	/**
	 * @param x
	 *            X position of the point
	 * @param y
	 *            Y position of the point
	 * @return Boolean stating if the point is inside the basic bounding box of
	 *         the sprite
	 */
	public boolean isPointInside(int x, int y) {
		return isPointInside(new Point(x, y));
	}

	/**
	 * @param pt
	 *            Point to be checked
	 * @return Boolean stating if the point is inside the basic bounding box of
	 *         the sprite
	 */
	public boolean isPointInside(Point pt) {
		if (pt.x < x)
			return false;
		if (pt.x > x + image.getWidth())
			return false;
		if (pt.y < y)
			return false;
		if (pt.y > y + image.getHeight())
			return false;
		return true;
	}

	public void setScale(float scale) {
		this.scale = scale;
	}
}
